﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Haozes.FxClient.Fetion2008
{
    public class Fetion2008Template
    {
        public readonly string NavServerUrl = "http://nav.fetion.com.cn/nav/getsystemconfig.aspx";

        public static string Tc()
        {
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("GET /nav/tc.aspx HTTP/1.1");
            sb.AppendLine("Host: nav.fetion.com.cn");
            sb.AppendLine("Connection: Close");
            sb.AppendLine("\r\n");
            return sb.ToString();
        }

        public static string GetSystemConfig(string mobile)
        {
            string xml = GetSystemConfigPostData(mobile);
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("POST /nav/getsystemconfig.aspx HTTP/1.1");
            sb.AppendLine("User-Agent: IIC2.0/PC 3.3.0370");
            sb.AppendLine("Host: nav.fetion.com.cn");
            sb.AppendLine("Content-Length: " + xml.Length + "");
            sb.AppendLine("Connection: Close");
            sb.AppendLine(string.Empty);
            sb.AppendLine(xml);
            return sb.ToString();
        }

        public static string GetSystemConfigPostData(string mobile)
        {
            string xml = "<config><user mobile-no=\"" + mobile + "\" /><client type=\"PC\" version=\"3.3.0370\" platform=\"W5.2\" /><servers version=\"0\" /><service-no version=\"0\" /><parameters version=\"0\" /><hints version=\"0\" /><http-applications version=\"0\" /><client-config version=\"0\" /></config>";
            return xml;
        }

        public static string RegesterSIPCStep1(string sid)
        {
            string arg = "<args><device type=\"PC\" version=\"0\" client-version=\"3.3.0370\" /><caps value=\"simple-im;im-session;temp-group;personal-group\" /><events value=\"contact;permission;system-message;personal-group\" /><user-info attributes=\"all\" /><presence><basic value=\"400\" desc=\"\" /></presence></args>";

            StringBuilder sb = new StringBuilder();
            sb.AppendLine("R fetion.com.cn SIP-C/2.0");
            sb.AppendLine("F: " + sid + "");
            sb.AppendLine("I: 1");
            sb.AppendLine("Q: 1 R");
            sb.AppendLine("L: " + arg.Length + "");
            sb.AppendLine(string.Empty);
            sb.AppendLine(arg);
            return sb.ToString();
        }

        public static string RegesterSIPCStep2(string sid, string response, string cnonce, string salt, string ssic)
        {
            string arg = "<args><device type=\"PC\" version=\"0\" client-version=\"3.3.0370\" /><caps value=\"simple-im;im-session;temp-group;personal-group\" /><events value=\"contact;permission;system-message;personal-group\" /><user-info attributes=\"all\" /><presence><basic value=\"400\" desc=\"\" /></presence></args>";
            StringBuilder sb = new StringBuilder();
            sb.AppendLine("R fetion.com.cn SIP-C/2.0");
            sb.AppendLine("F: " + sid + "");
            sb.AppendLine("I: 1");
            sb.AppendLine("Q: 2 R");
            sb.AppendLine(string.Format("A: Digest algorithm=\"SHA1-sess\",response=\"{0}\",cnonce=\"{1}\",salt=\"{2}\",ssic=\"{3}\"", response, cnonce, salt, ssic));
            sb.AppendLine("L: " + arg.Length + "");
            sb.AppendLine(string.Empty);
            sb.AppendLine(arg);

            return sb.ToString();
        }
        /******************************************************************************/
    }
}
